package calcu_tabla_simbolos;
import java_cup.runtime.*;
import java.io.*;
%%
%{
    private TablaSimbolos tabla;
    public Yylex(Reader in, TablaSimbolos t){
    this(in);
    this.tabla= t;
    };
%}
%unicode
%cup
%line
%column
%line

Decimal =  0 | [1-9][0-9]* | {signos}0 | {signos}  [1-9][0-9]*
Flotante =  0  \.  [1-9][0-9]*  | [1-9][0-9]*  \. [1-9][0-9]* |  \. [1-9][0-9]*  | {signos} 0  \.  [1-9][0-9]*  | {signos} [1-9][0-9]*  \. [1-9][0-9]* |{ signos}  \. [1-9][0-9]*
listacadena =   \" [a-zA-Z0-9" "]* \"     //se usa * porque puede ser cadena vacia
//booleano = "VERDADERO" | "verdadero" | "FALSO" | "falso"
FindeLinea = \n|\r|\r\n
espacion = " "
signos=   \-
var = \$ [a-zA-Z][a-zA-Z0-9]*
%%
"+" {return new Symbol(sym.MAS);}
"*" {return new Symbol(sym.POR);}
"/" {return new Symbol(sym.ENTRE);}
"-" { return new Symbol(sym.MENOS);}
";" {return new Symbol(sym.PUNTOYCOMA);}
"(" {return new Symbol(sym.LPAREN);}
")" {return new Symbol(sym.RPAREN);}
":=" {return new Symbol(sym.ASIGNA);}
"&" {return new Symbol(sym.LAND); }
"|" {return new Symbol(sym.LOR); }
">" {return new Symbol(sym.MAYOR);}
"<" {return new Symbol(sym.MENOR);}
"VERDADERO" | "verdadero" | "FALSO" | "falso"  {return new Symbol(sym.VF, yytext()); }
"SQR"|"sqr"  {return new Symbol(sym.ELEVADO); }
"INICIO:"| "inicio:" {return new Symbol(sym.BEGIN);}
"FIN"| "fin" {return new Symbol(sym.END);}
"DECLARACION VARIABLES:"| "declaracion variables:" {return new Symbol(sym.IVARIABLES);}
"FIN VARIABLES"| "fin variables"         {return new Symbol(sym.FVARIABLES);}
"entero"  |"ENTERO"    { return new Symbol(sym.ENTERO);}
"cadena"  |"CADENA"    { return new Symbol(sym.CADENA);}
"booleano"|"BOOLEANO"  { return new Symbol(sym.BOOLEANO);}
"decimal" |"DECIMAL"   { return new Symbol(sym.DECIMAL);}
"estructura" |"ESTRUCTURA"   { return new Symbol(sym.ESTRUCTURA);}
"[" {return new Symbol(sym.LCORCHETE);}
"]" {return new Symbol(sym.RCORCHETE);}
","    {return new Symbol(sym.COMA);}
"IMPRIMIR" | "imprimir"  {return new Symbol(sym.IMPRIMIR);}
"OBTENER"  | "obtener"   {return new Symbol(sym.OBTENER); }
"CONCATENAR" | "concatenar"   {return new Symbol(sym.CONCATENAR); }
{var} { return new Symbol(sym.LETRAEST,yytext());}
[:jletter:][:jletterdigit:]* | [:jletter:][:jletterdigit:]* \. [:jletter:][:jletterdigit:]*
                              {
                                Simbolo s;
                                if ( (s = (tabla.buscar( yytext()))) == null)
                                  s= new Simbolo(yytext(),yyline,yycolumn);
                                return new Symbol(sym.LETRA,s);

                               }

 {Decimal}     {return new Symbol(sym.NENTERO,  new Integer(yytext())); }
 {Flotante}    {return new Symbol(sym.NREAL,  new Float(yytext())); }
 {listacadena} {return new Symbol(sym.TEXTO,yytext());}
 {FindeLinea} {}
 {espacion}     { }
. { System.err.println("Caracter invalido: "+yytext()+"["+yyline+":"+yycolumn+"]"); }